package com.shqcjd.preinstallmobile.api;

import com.lzy.okgo.OkGo;
import com.lzy.okrx2.adapter.ObservableBody;
import com.shqcjd.preinstallmobile.helper.JsonConvert;
import com.shqcjd.preinstallmobile.model.DefectInfoBean;
import com.shqcjd.preinstallmobile.model.ResponseData;
import com.shqcjd.preinstallmobile.model.pojo.AbnormalBean;
import com.shqcjd.preinstallmobile.model.pojo.DefectManageBean;
import com.shqcjd.preinstallmobile.model.pojo.DefectManageTypeBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentAbnormalBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentGroupBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentInfoBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentInfoInspectBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentInspectionBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentListBean;
import com.shqcjd.preinstallmobile.model.pojo.ExpertBean;
import com.shqcjd.preinstallmobile.model.pojo.ExpertListBean;
import com.shqcjd.preinstallmobile.model.pojo.FileBean;
import com.shqcjd.preinstallmobile.model.pojo.GuideListBean;
import com.shqcjd.preinstallmobile.model.pojo.IndexBean;
import com.shqcjd.preinstallmobile.model.pojo.InspectionRecordBean;
import com.shqcjd.preinstallmobile.model.pojo.InspectionStandardBean;
import com.shqcjd.preinstallmobile.model.pojo.InspectionListBean;
import com.shqcjd.preinstallmobile.model.pojo.InspectionTaskBean;
import com.shqcjd.preinstallmobile.model.pojo.IntentEquipmentBean;
import com.shqcjd.preinstallmobile.model.pojo.LoginBean;
import com.shqcjd.preinstallmobile.model.pojo.MoreImgListBean;
import com.shqcjd.preinstallmobile.model.pojo.MsgBean;
import com.shqcjd.preinstallmobile.model.pojo.PlayBackBean;
import com.shqcjd.preinstallmobile.model.pojo.PointInfoBean;
import com.shqcjd.preinstallmobile.model.pojo.ProcessBackBean;
import com.shqcjd.preinstallmobile.model.pojo.NewsDetailBean;
import com.shqcjd.preinstallmobile.model.pojo.NewsListBean;
import com.shqcjd.preinstallmobile.model.pojo.RouteInfoBean;
import com.shqcjd.preinstallmobile.model.pojo.RouteInfoListBean;
import com.shqcjd.preinstallmobile.model.pojo.RouteListBean;
import com.shqcjd.preinstallmobile.model.pojo.TaskCodeBean;
import com.shqcjd.preinstallmobile.model.pojo.TaskNtrackBean;
import com.shqcjd.preinstallmobile.model.pojo.TrackInfoBean;

import org.json.JSONObject;

import java.io.File;
import java.util.List;

import io.reactivex.Observable;

/**
 * Created by sy on 2019/3/14.
 */

public class ApiService {
    public static Observable<ResponseData<LoginBean>> login(JSONObject loginBean) {
        return OkGo.<ResponseData<LoginBean>>post(HttpUrl.LOGIN)
                .upJson(loginBean)
                .converter(new JsonConvert<ResponseData<LoginBean>>(){})
                .adapt(new ObservableBody<ResponseData<LoginBean>>());

    }

    public static Observable<ResponseData<IndexBean>> index(){
        return OkGo.<ResponseData<IndexBean>>get(HttpUrl.INDEX_DATA)
                .converter(new JsonConvert<ResponseData<IndexBean>>(){})
                .adapt(new ObservableBody<ResponseData<IndexBean>>());
    }

    public static Observable<ResponseData<InspectionListBean>> getInspectionList(JSONObject parameter){
        return OkGo.<ResponseData<InspectionListBean>>post(HttpUrl.GET_TASK_LIST)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<InspectionListBean>>(){})
                .adapt(new ObservableBody<ResponseData<InspectionListBean>>());

    }

    public static Observable<ResponseData<GuideListBean>> getGuideList(JSONObject parameter){
        return OkGo.<ResponseData<GuideListBean>>post(HttpUrl.GET_GUIDE_LIST)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<GuideListBean>>(){})
                .adapt(new ObservableBody<ResponseData<GuideListBean>>());

    }

    public static Observable<ResponseData<ExpertListBean>> getExpertList(JSONObject parameter){
        return OkGo.<ResponseData<ExpertListBean>>post(HttpUrl.GET_EXPERT_LIST)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<ExpertListBean>>(){})
                .adapt(new ObservableBody<ResponseData<ExpertListBean>>());

    }

    public static Observable<ResponseData<ExpertBean>> getExper(int id){
        return OkGo.<ResponseData<ExpertBean>>get(HttpUrl.GET_EXPERT)
                .params("id", id)
                .converter(new JsonConvert<ResponseData<ExpertBean>>() {
                })
                .adapt(new ObservableBody<ResponseData<ExpertBean>>());

    }

    public static Observable<ResponseData<RouteListBean>> routeListHttp(JSONObject routeBean) {
        return OkGo.<ResponseData<RouteListBean>>post(HttpUrl.ROUTE_LIST)
                .upJson(routeBean)
                .converter(new JsonConvert<ResponseData<RouteListBean>>(){})
                .adapt(new ObservableBody<ResponseData<RouteListBean>>());

    }

    public static Observable<ResponseData<RouteInfoBean>> routeInfoHttp(int rId) {
        return OkGo.<ResponseData<RouteInfoBean>>get(HttpUrl.ROUTE_INFO+"?id="+rId)
                .converter(new JsonConvert<ResponseData<RouteInfoBean>>(){})
                .adapt(new ObservableBody<ResponseData<RouteInfoBean>>());
    }

    public static Observable<ResponseData<RouteInfoListBean>> routeInfoListHttp(int pageIndex, int pageSize, int rId) {
        return OkGo.<ResponseData<RouteInfoListBean>>get(HttpUrl.ROUTE_INFO_LIST+"?pageIndex="+pageIndex+"&pageSize="+pageSize+"&patrol_route_id="+rId)
                .converter(new JsonConvert<ResponseData<RouteInfoListBean>>(){})
                .adapt(new ObservableBody<ResponseData<RouteInfoListBean>>());
    }

    public static Observable<ResponseData<InspectionStandardBean>> inspectionStandardHttp(int eId) {
        return OkGo.<ResponseData<InspectionStandardBean>>get(HttpUrl.INSPECTION_STANDARD+"?equipment_id="+eId)
                .converter(new JsonConvert<ResponseData<InspectionStandardBean>>(){})
                .adapt(new ObservableBody<ResponseData<InspectionStandardBean>>());
    }

    public static Observable<ResponseData<DefectInfoBean>> defectInfoHttp(int dId) {
        return OkGo.<ResponseData<DefectInfoBean>>get(HttpUrl.DEFECT_INFO+"?id="+dId)
                .converter(new JsonConvert<ResponseData<DefectInfoBean>>(){})
                .adapt(new ObservableBody<ResponseData<DefectInfoBean>>());
    }

    public static Observable<ResponseData<DefectManageBean>> defectManageHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<DefectManageBean>>post(HttpUrl.DEFECT_MANAGE_LIST)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<DefectManageBean>>(){})
                .adapt(new ObservableBody<ResponseData<DefectManageBean>>());
    }

    public static Observable<ResponseData<MoreImgListBean>> playBackMoreImgHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<MoreImgListBean>>post(HttpUrl.PLAY_BACK_MORE_IMG_LIST)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<MoreImgListBean>>(){})
                .adapt(new ObservableBody<ResponseData<MoreImgListBean>>());
    }

    public static Observable<ResponseData<EquipmentInfoBean>> equipmentInfoHttp(String kks) {
        return OkGo.<ResponseData<EquipmentInfoBean>>get(HttpUrl.EUIPMENT_INFO+"?kks="+kks)
                .converter(new JsonConvert<ResponseData<EquipmentInfoBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentInfoBean>>());
    }


    public static Observable<ResponseData<EquipmentInfoInspectBean>> equipmentInfoInspectRecordHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<EquipmentInfoInspectBean>>post(HttpUrl.INSPECT_RECORD)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<EquipmentInfoInspectBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentInfoInspectBean>>());
    }


    public static Observable<ResponseData<NewsListBean>> getNewsList(JSONObject parameter){
        return OkGo.<ResponseData<NewsListBean>>post(HttpUrl.GET_NEWS_LIST)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<NewsListBean>>(){})
                .adapt(new ObservableBody<ResponseData<NewsListBean>>());

    }


    public static Observable<ResponseData<NewsDetailBean>> getNewsDetail(int id){
        return OkGo.<ResponseData<NewsDetailBean>>get(HttpUrl.GET_NEWS_DETAIL)
                .params("id", id)
                .converter(new JsonConvert<ResponseData<NewsDetailBean>>() {
                })
                .adapt(new ObservableBody<ResponseData<NewsDetailBean>>());

    }

    public static Observable<ResponseData<EquipmentGroupBean>> equipmentGroupHttp(int tId, String kks) {
        return OkGo.<ResponseData<EquipmentGroupBean>>get(HttpUrl.EQUIPMENT_GROUP+"?kks="+kks+"&task_id="+tId)
                .converter(new JsonConvert<ResponseData<EquipmentGroupBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentGroupBean>>());
    }

    public static Observable<ResponseData<EquipmentAbnormalBean>> equipmentAbnormalHttp(int tId, int eId) {
        return OkGo.<ResponseData<EquipmentAbnormalBean>>get(HttpUrl.EQUIPMENT_ABNORMAL+"?equipment_id="+eId+"&task_id="+tId)
                .converter(new JsonConvert<ResponseData<EquipmentAbnormalBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentAbnormalBean>>());
    }

    public static Observable<ResponseData<EquipmentInspectionBean>> equipmentInspectionHttp(int task_id, String kks) {
        return OkGo.<ResponseData<EquipmentInspectionBean>>get(HttpUrl.EQUIPMENT_INSPECTION+"?task_id="+task_id+"&kks="+kks)
                .converter(new JsonConvert<ResponseData<EquipmentInspectionBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentInspectionBean>>());
    }

    public static Observable<ResponseData<PlayBackBean>> playBackHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<PlayBackBean>>post(HttpUrl.PLAY_BACK)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<PlayBackBean>>(){})
                .adapt(new ObservableBody<ResponseData<PlayBackBean>>());
    }

    public static Observable<ResponseData<ProcessBackBean>> processBackHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<ProcessBackBean>>post(HttpUrl.PROCESS_BACK)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<ProcessBackBean>>(){})
                .adapt(new ObservableBody<ResponseData<ProcessBackBean>>());
    }

    public static Observable<ResponseData<EquipmentListBean>> equipmentListHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<EquipmentListBean>>post(HttpUrl.EUIPMENT_LIST)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<EquipmentListBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentListBean>>());
    }

    public static Observable<ResponseData<InspectionRecordBean>> inspectRecordHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<InspectionRecordBean>>post(HttpUrl.INSPECT_RECORD)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<InspectionRecordBean>>(){})
                .adapt(new ObservableBody<ResponseData<InspectionRecordBean>>());
    }

    public static Observable<ResponseData<IntentEquipmentBean>> intentEquipmentHttp(String kks, int task_id) {
        return OkGo.<ResponseData<IntentEquipmentBean>>get(HttpUrl.INTENT_EQUIPMENT+"?kks="+kks+"&task_id="+task_id)
                .converter(new JsonConvert<ResponseData<IntentEquipmentBean>>(){})
                .adapt(new ObservableBody<ResponseData<IntentEquipmentBean>>());
    }

    public static Observable<ResponseData<List<DefectManageTypeBean>>> defectManageTypeHttp() {
        return OkGo.<ResponseData<List<DefectManageTypeBean>>>get(HttpUrl.DEFECT_MANAGE_TYPE)
                .converter(new JsonConvert<ResponseData<List<DefectManageTypeBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<DefectManageTypeBean>>>());
    }

    public static Observable<ResponseData<List<DefectManageTypeBean>>> playBackTypeHttp() {
        return OkGo.<ResponseData<List<DefectManageTypeBean>>>get(HttpUrl.PLAY_BACK_TYPE)
                .converter(new JsonConvert<ResponseData<List<DefectManageTypeBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<DefectManageTypeBean>>>());
    }

    public static Observable<ResponseData<Integer>> putCheckResultHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<Integer>>post(HttpUrl.PUT_CHECK_RESULT)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<Integer>>(){})
                .adapt(new ObservableBody<ResponseData<Integer>>());
    }

    public static Observable<ResponseData> openOrCloseSwitchHttp(String kks) {
        return OkGo.<ResponseData>get(HttpUrl.OPEN_OR_CLOSE_EQUIPMENT+"?kks="+kks)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData<List<PointInfoBean>>> routePointInfoHttp(int patrol_point_id, int patrol_route_id) {
        return OkGo.<ResponseData<List<PointInfoBean>>>get(HttpUrl.ROUTE_POINT_INFO+"?patrol_point_id="+patrol_point_id+"&patrol_route_id="+patrol_route_id)
                .converter(new JsonConvert<ResponseData<List<PointInfoBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<PointInfoBean>>>());
    }

    /**
     * 独立设备巡检页 点击读取按钮的接口
     * @return
     */
    public static Observable<ResponseData<String>> equipmentInspectionButtonHttp(String url, int equipmentId, String type, int equipmentPartItemId) {
        return OkGo.<ResponseData<String>>get(url+"?equipmentId="+equipmentId+"&type="+type+"&equipmentPartItemId="+equipmentPartItemId)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }
    public static Observable<ResponseData<String>> createGuide(JSONObject jsonObject) {
        return OkGo.<ResponseData<String>>post(HttpUrl.CREATE_GUIDE)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData<FileBean>> uploadFile(File file) {
        return OkGo.<ResponseData<FileBean>>post(HttpUrl.UPLOAD_FILE)
                .params("file", file)
                .converter(new JsonConvert<ResponseData<FileBean>>(){})
                .adapt(new ObservableBody<ResponseData<FileBean>>());
    }

    public static Observable<ResponseData> sendFile(JSONObject jsonObject) {
        return OkGo.<ResponseData>post(HttpUrl.SEND_FILE)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData<List<FileBean>>> getFileList(String roomId) {
        return OkGo.<ResponseData<List<FileBean>>>get(HttpUrl.GET_FILE_LIST+roomId)
                .converter(new JsonConvert<ResponseData<List<FileBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<FileBean>>>());
    }

    public static Observable<ResponseData> handleGuide(JSONObject jsonObject) {
        return OkGo.<ResponseData>post(HttpUrl.HANDLE_GUIDE)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData<String>> word2pf(String url) {
        return OkGo.<ResponseData<String>>post(HttpUrl.WORD_2_PDF)
                .params("url",url)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData<List<FileBean>>> getGuideFileList(int id) {
        return OkGo.<ResponseData<List<FileBean>>>get(HttpUrl.GUIDE_FILE_LIST)
                .params("remoteGuideId",id)
                .converter(new JsonConvert<ResponseData<List<FileBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<FileBean>>>());
    }

    public static Observable<ResponseData<MsgBean>> getMsgList(int pageIndex,int pageSize) {
        return OkGo.<ResponseData<MsgBean>>get(HttpUrl.MSG_LIST)
                .params("pageIndex",pageIndex)
                .params("pageSize",pageSize)
                .converter(new JsonConvert<ResponseData<MsgBean>>(){})
                .adapt(new ObservableBody<ResponseData<MsgBean>>());
    }

    public static Observable<ResponseData<Integer>> unread() {
        return OkGo.<ResponseData<Integer>>get(HttpUrl.UNREAD)
                .converter(new JsonConvert<ResponseData<Integer>>(){})
                .adapt(new ObservableBody<ResponseData<Integer>>());
    }

    public static Observable<ResponseData<InspectionTaskBean>> getCheckList(int taskId) {
        return OkGo.<ResponseData<InspectionTaskBean>>get(HttpUrl.GET_CHECK_LIST)
                .params("taskId",taskId)
                .params("pageIndex",0)
                .params("pageSize",999)
                .converter(new JsonConvert<ResponseData<InspectionTaskBean>>(){})
                .adapt(new ObservableBody<ResponseData<InspectionTaskBean>>());
    }

    public static Observable<ResponseData<List<String>>> uploadMultiImg(List<File> files) {
        return OkGo.<ResponseData<List<String>>>post(HttpUrl.UPLOAD_MULTI_IMG)
                .addFileParams("file", files)
                .converter(new JsonConvert<ResponseData<List<String>>>(){})
                .adapt(new ObservableBody<ResponseData<List<String>>>());
    }

    public static Observable<ResponseData<String>> putCheckException(String jsonObject) {
        return OkGo.<ResponseData<String>>post(HttpUrl.PUT_CHECK_EXCEPTION)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }


    public static Observable<ResponseData<TaskCodeBean>> getRandomTask() {
        return OkGo.<ResponseData<TaskCodeBean>>get(HttpUrl.CREATE_RANDOM_TASK)
                .converter(new JsonConvert<ResponseData<TaskCodeBean>>(){})
                .adapt(new ObservableBody<ResponseData<TaskCodeBean>>());
    }

    public static Observable<ResponseData<List<DefectManageTypeBean>>> getInspectionUser() {
        return OkGo.<ResponseData<List<DefectManageTypeBean>>>get(HttpUrl.GET_INSPECTION_USER)
                .converter(new JsonConvert<ResponseData<List<DefectManageTypeBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<DefectManageTypeBean>>>());
    }

    public static Observable<ResponseData> getGroupTrue(int task_id, int equipment_id) {
        return OkGo.<ResponseData>get(HttpUrl.GET_GROUP_TRUE+"?task_id="+task_id+"&equipment_id="+equipment_id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData<AbnormalBean>> getAbnormalInfo(int task_id, int equipment_id, int equipment_part_item_id, String value) {
        return OkGo.<ResponseData<AbnormalBean>>get(HttpUrl.GET_ABNORMAL_INFO+"?task_id="+task_id+"&equipment_id="+equipment_id+"&equipment_part_item_id="+equipment_part_item_id+"&value="+value)
                .converter(new JsonConvert<ResponseData<AbnormalBean>>(){})
                .adapt(new ObservableBody<ResponseData<AbnormalBean>>());
    }

    public static Observable<ResponseData<TaskNtrackBean>> getNtrackList(JSONObject parameter){
        return OkGo.<ResponseData<TaskNtrackBean>>post(HttpUrl.GET_TASK_NTRACK)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<TaskNtrackBean>>(){})
                .adapt(new ObservableBody<ResponseData<TaskNtrackBean>>());

    }

    public static Observable<ResponseData<TrackInfoBean>> getTrackInfo(int task_id, int route_id) {
        return OkGo.<ResponseData<TrackInfoBean>>get(HttpUrl.GET_TRACK_INFO+"?task_id="+task_id+"&route_id="+route_id)
                .converter(new JsonConvert<ResponseData<TrackInfoBean>>(){})
                .adapt(new ObservableBody<ResponseData<TrackInfoBean>>());
    }

    public static Observable<ResponseData> setSysMsgRead(String msgId){
        return OkGo.<ResponseData>post(HttpUrl.SET_SYSMSG_READ+msgId)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }
}
